package com.me.darkness_is_coming.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.Align;
import com.badlogic.gdx.utils.viewport.StretchViewport;
import com.me.darkness_is_coming.actors.GUIElement;
import com.me.darkness_is_coming.actors.MenuButton;
import com.me.darkness_is_coming.actors.RulesContent;

public class RulesScreen implements Screen
{
    private Texture background_image;
    private SpriteBatch batch;
    private SpriteBatch text_batch;
    private OrthographicCamera camera;
    private Stage stage;
    private MenuButton homeButton;
    private BitmapFont font;
    //--------------------------
    private ScrollPane scroller;
    private Table table;
    private TextureAtlas darknessImages;
    private TextureRegion darkness;
    private static final String reallyLongString = "This Is A Really Long String That Has Lots Of Lines And Repeats."
            + "This Is A Really Long String That Has Lots Of Lines And Repeats."
            + "This Is A Really Long String That Has Lots Of Lines And Repeats.";
    RulesContent rc;
    //-----------------------------------------------

    public RulesScreen(SpriteBatch batch)
    {
        this.batch = batch;
        text_batch = new SpriteBatch();

        table = new Table();
        darknessImages = new TextureAtlas(Gdx.files.internal("data/Darkness/Darkness.atlas"));
        darkness = new TextureRegion(darknessImages.findRegion("Darkness01"));
        GUIElement ge = new GUIElement(darkness, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        table.setSize(Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 0.65f);
        table.setPosition(Gdx.graphics.getWidth() * 0.15f, Gdx.graphics.getHeight() * 0.18f);
        rc = new RulesContent(0, Gdx.graphics.getHeight() * (0.65f - 2.0f), Gdx.graphics.getWidth() * 0.7f, Gdx.graphics.getHeight() * 2.0f, table.getWidth(), table.getHeight());
        scroller = new ScrollPane(rc);
        table.add(scroller).fill().expand();
        System.out.println("pos Scroller:" + scroller.getX() + " " + scroller.getY());
        System.out.println("pos Table:" + table.getX() + " " + table.getY());
        System.out.println("pad Table:" + table.getPadX() + " " + table.getPadY());

        background_image = new Texture("data/Fons/RulesFon.png");
        FreeTypeFontGenerator gen = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/CooperBlackStd.otf"));
        FreeTypeFontGenerator.FreeTypeFontParameter font_parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        font_parameter.size = (int)(Gdx.graphics.getWidth() * 0.03f);
        font = gen.generateFont(font_parameter);
        font.setColor(240f/255f, 232f/255f, 3f/255f, 1.0f);

        homeButton = new MenuButton(new Texture("data/Menu/MenuButtonBack.png"), MenuButton.HOME, Gdx.graphics.getWidth()*0.238f, Gdx.graphics.getHeight()*0.117f, Gdx.graphics.getWidth()*0.523f, Gdx.graphics.getWidth()*0.083f);
        stage = new Stage(new StretchViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
        System.out.println("pos Scroller:" + scroller.getX() + " " + scroller.getY());
        System.out.println("pos Table:" + table.getX() + " " + table.getY());
        System.out.println("pad Table:" + table.getPadX() + " " + table.getPadY());
        stage.addActor(table);
        stage.addActor(homeButton);
    }

    @Override
    public void render(float delta)
    {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        batch.draw(background_image, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        batch.end();
        stage.act(delta);
        stage.draw();
    }

    @Override
    public void resize(int width, int height)
    {
        stage.getViewport().update(width, height, false);
    }
    @Override
    public void show()
    {
        Gdx.input.setInputProcessor(stage);
    }
    @Override
    public void hide()
    {
        //
    }
    @Override
    public void pause()
    {
        //
    }
    @Override
    public void resume()
    {
        //
    }
    @Override
    public void dispose()
    {
        stage.dispose();
        text_batch.dispose();
        font.dispose();
        background_image.dispose();
        darknessImages.dispose();
        homeButton.dispose();
        rc.dispose();
    }
}
